package wei.qiang.ye.springbootmybatis.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wei.qiang.ye.springbootmybatis.dao.UserDOMapper;
import wei.qiang.ye.springbootmybatis.dto.MvcDataDto;
import wei.qiang.ye.springbootmybatis.entity.UserDO;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserDOMapper userDOMapper;

    @Override
    public void add(UserDO userDO) {
        userDOMapper.insert(userDO);
    }

    @Override
    public void edit(UserDO userDO) {
        userDOMapper.updateByPrimaryKey(userDO);
    }

    @Override
    public void delete(int id) {
        userDOMapper.deleteByPrimaryKey(id);
    }

    @Override
    public UserDO getById(int id) {
        return userDOMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<UserDO> listPages(MvcDataDto param) {
        int pageNum = param.getPage().getPageNum();
        int pageSize = param.getPage().getPageSize();
        //翻页关键，调用插件的翻页方法，把前端的翻页数据传进插件
        PageHelper.startPage(pageNum , pageSize);
        List<UserDO> userDOList = userDOMapper.listPages();
        return new PageInfo<>(userDOList);
    }
}
